define(function(require, exports, module) {
    var router = require("router");
    //var app = require("app");
    var controller = {};
    controller.vue = function(params) {
        controller.vm = new Vue({
            router: router,
            data: function data() {
                return {
                     
                    page: 1,
                    lastPage:0,
                    mounted: 0,
                    listData: [],
                    nodata:0,
                    id:95,
                    community_id:0,
                    groupData: {}
                                 

                };
            },
            el: "#pageVoteIndex",
            created: function created() {
                this.community_id = this.$route.params.community_id;
                this.getTopicList();
                this.getGroup();

            },

            mounted: function mounted() {
                    if (this.mounted == 1) {
                        return;
                    }
                    
                    var that = this ;
                    app.pager("#pageVoteIndex",function(){
                       that.getTopicList();
                    });
                    this.mounted = 1;
            },
            methods: {
             
                 //
                getGroup: function () {
                  var that = this;
                  var id = this.id;
                  app.get("sns/group/find", {
                    id: id,
                  }, function (res) {
                    if (res.code != 200) {
                      app.alert(res.msg);
                      return;
                    }
                    
                    that.setData({ groupData: res.data });
                  })
                },


                //api evens/list 活动列表 
                getTopicList: function (reset = 0) {
                  var that = this;
                  // var order_by = that.showOrder;
                  //重新加载 
                   
                  if (this.loading == 1 || this.lastpage == 1) {
                    return false;
                  }
                  this.loading = 1;
                  //   lastpage:0,
                  var page = that.page;
                  //console.log(event_type);
                  app.get("sns/topic/list", {
                    page: page,
                    //status: 1,
                    
                    pid: this.id,
                    fields: 'id,user_id,cate_id,cover,title,addtime,desc,content,dateline,lastupdate,pid,pid2,type,status,pics,user,group,statistics.comment_count,statistics.join_count,statistics.hit_count,statistics.inc_money,statistics.good_count,video_url,thumb_up_ed,videoKey,imageKeys,content_data,vote_count,SnsTopicStatistics.good_count,SnsTopicStatistics.comment_count',
                    order: 'id desc',
                    limit: 15,
                  }, function (res) {
                    that.loading = 0;
                    if (res.code != 200) {
                      app.alert(res.msg);
                      return;
                    }
                    if (res.data.list.length === 0) {
                      that.lastpage = 1;
                    }
                    page++;
                    that.setData({ page: page, listData: that.listData.concat(res.data.list) });
                    if( that.listData.length === 0){
                      that.nodata=1;
                    }

                  })
                },
                
                apply1: function () {
                  
                },
               
                setData:function(data){
                     for(var i in data){
                        this[i]=data[i];
                     }
                  }
                    
              }
        }).$mount("#app");
    };
    controller.pageShow = function() {};
    module.exports = controller;
});
